package com.homedo.odin.solution.enumcode.hebi;

import java.util.Arrays;
import lombok.Getter;

/**
 * @author: zhanglei
 * @date: 2018/4/17
 * @Description: 河币订单状态
 */
@Getter
public enum HebiOrderStatusEnum {
    FREEZE("freeze", "冻结"),
    RESTITUTION("restitution", "返还"),
    ROLLOUT("rollout", "转出"),
    FAIL("fail", "订单支付失败"),
    PROFIT("profit", "收入");

    private String dbValue;
    private String displayValue;

    HebiOrderStatusEnum(String dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }


    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(HebiOrderStatusEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(HebiOrderStatusEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(HebiOrderStatusEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
